import {
  Directive, DoCheck, ElementRef, EventEmitter, Input, OnChanges, OnInit, Output,
  SimpleChanges
} from '@angular/core';
import * as echarts from 'echarts';

import {ChartsService} from "../charts.service";
@Directive({
  selector: 'echarts'
})
export class EchartOptionDirective implements  OnInit{

  @Input('chartType')
  chartType: any;

  @Output()
  public chartEmit: EventEmitter<any>=new EventEmitter();

  constructor(private el: ElementRef,public chartser: ChartsService) { }

  ngOnInit(): void {
    let chart =  echarts.init(this.el.nativeElement);
    chart.setOption(this.chartType);
    this.chartEmit.emit(chart);
    this.chartser.add(chart);
    var charts = this.chartser.get();
    window.onresize = function () {
      charts.map(function(item){
        item.resize()
      })
    }
  }
}
